package com.example.hellogridview;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Toast;

public class ImageAdapterHelloGridView extends BaseAdapter{

	private static final String GETVIEW_METHOD = "ImageAdapterGetView";
	private static final String CLASS_STARTED = "ImageAdapterInstantiated";
	private Context mContext;
	private Cursor thumbIdCursor;
	/* private int[] mThumbIds = {
			R.drawable.sample_0, R.drawable.sample_1, R.drawable.sample_2, R.drawable.sample_3,
			R.drawable.sample_4, R.drawable.sample_5, R.drawable.sample_6, R.drawable.sample_7,
			R.drawable.sample_0, R.drawable.sample_1, R.drawable.sample_2, R.drawable.sample_3,
			R.drawable.sample_4, R.drawable.sample_5, R.drawable.sample_6, R.drawable.sample_7,
			R.drawable.sample_0, R.drawable.sample_1, R.drawable.sample_2, R.drawable.sample_3,
			R.drawable.sample_4, R.drawable.sample_5, R.drawable.sample_6, R.drawable.sample_7,
			R.drawable.sample_0, R.drawable.sample_1, R.drawable.sample_2, R.drawable.sample_3,
			R.drawable.sample_4, R.drawable.sample_5, R.drawable.sample_6, R.drawable.sample_7,
			R.drawable.sample_0, R.drawable.sample_1, R.drawable.sample_2, R.drawable.sample_3,
			R.drawable.sample_4, R.drawable.sample_5, R.drawable.sample_6, R.drawable.sample_7,
			R.drawable.sample_0, R.drawable.sample_1, R.drawable.sample_2, R.drawable.sample_3,
			R.drawable.sample_4, R.drawable.sample_5, R.drawable.sample_6, R.drawable.sample_7,
			R.drawable.sample_0, R.drawable.sample_1, R.drawable.sample_2, R.drawable.sample_3,
			R.drawable.sample_4, R.drawable.sample_5, R.drawable.sample_6, R.drawable.sample_7,
			R.drawable.sample_0, R.drawable.sample_1, R.drawable.sample_2, R.drawable.sample_3,
			R.drawable.sample_4, R.drawable.sample_5, R.drawable.sample_6, R.drawable.sample_7,
			
	};
	*/
	
	
	
	public ImageAdapterHelloGridView(Context c, Cursor cursor){
		mContext = c;
		thumbIdCursor = cursor;
		String columnName = cursor.getColumnName(0);
		int totalRows = cursor.getCount();
		Log.i("ImageAdapter", "The cursor column 0 name is " + columnName);
		Log.i("ImageAdapter", "The total number of rows in the cursor is " + totalRows);
		Log.i(CLASS_STARTED, "Constructor complete");
		
	}
	
	@Override
	public int getCount() {
		
		return 0;
	}

	@Override
	public Object getItem(int position) {
		
		return null;
	}

	@Override
	public long getItemId(int position) {
		
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Log.i("ImageAdapter", "Getting View number: " + position);
		ImageView imageView;
		if(convertView == null){
			Log.i("ImageAdapter", "No view detected, creating new view...");
			imageView = new ImageView(mContext);
			imageView.setLayoutParams(new GridView.LayoutParams(200,200));
			imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
			imageView.setPadding(1, 1, 1, 1);
		}else{
			imageView = (ImageView) convertView;
		}
		String columnName = thumbIdCursor.getColumnName(0);
		Log.i(GETVIEW_METHOD, "The column name in the cursor is " + columnName);
		//imageView.setImageResource(mThumbIds[position]);
		thumbIdCursor.moveToPosition(position);
		int imageId = thumbIdCursor.getInt(0);
		thumbIdCursor.close();
		imageView.setImageURI(Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, "" + imageId));
		
		Log.i("ImageAdapter","Returning imageView");
		return imageView;
	}
		

}
